package algorithm.easy;

public class Solution111 {
    //输入：root = [3,9,20,null,null,15,7]
    //输出：2
    //输入：root = [2,null,3,null,4,null,5,null,6]
    //输出：5
    public static int minDepth(TreeNode root) {
        if(root==null){
            return 0;
        }
        if(root.left==null && root.right!=null){
            return minDepth(root.right)+1;
        }
        if(root.left!=null && root.right==null){
            return minDepth(root.left)+1;
        }

        return Math.min(minDepth(root.left),minDepth(root.right)) +1;
    }


    public static void main(String[] args){

        TreeNode treeNode = TreeNode.init110();
        System.out.println(minDepth(treeNode));
    }
}
